﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class RecycledNumbers
    {
        public RecycledNumbers()
        {
            int testCount = Int32.Parse(TestConsole.ReadLine());
            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                string[] input = TestConsole.ReadLine().Split(' ');
                int a = Int32.Parse(input[0]);
                int b = Int32.Parse(input[1]);
                int count = 0;
                
                for (int i = a; i <= b; i++)
                {
                    string s = i.ToString();
                    int[] distinct = new int[b + 1];
                    for (int j = 1; j < s.Length; j++)
                    {
                        
                        if (s[j] < s[0])
                        {
                            continue;
                        }
                        
                        string recycled = s.Substring(j);
                        string pre = s.Substring(0, j);
                        
                        string reStr = recycled + pre;
                        int reA = Int32.Parse(reStr);

                        if (reA <= b && reA > i)
                        {
                            
                            distinct[reA] = 1;
                            //Console.WriteLine(i.ToString() + " " + reA.ToString());
                            count++;
                            
                        }
                         
                    }
                     
                }
                Console.WriteLine("Case #" + testCase + ": " + count);
            }
        }
    }
}
